<template>
	<div class="add-jq-dialog">
		<!--添加仓库-->
		
		
		<appdialog 
			ref="dialog"
			:visible="false" 
			title="选择文件"
			width="30%"
			@confirm="confirmAdd"
			@cancle="cancleAdd"
			>
      <div style="text-align:center;" v-loading="loading">
         <h4 v-show="isshow">已选择:{{nowChoose}}</h4>
         <el-tree :data="treedata" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
      </div>
		</appdialog>
		
		
		
	</div>
</template>

<script>

import appdialog from "@/view/components/dialog/dialog";
import { getDirFile,syncFile} from '@/service/swagger/ShareController.js'
//遍历文件树 给文件夹加disable
// const  bianli = function(arr) {
// 	if(arr&&arr.length){
//     arr.forEach(el=>{
//       if(arr.fileType == 1){
//         arr.disabled = true
//       }else{
//         arr.disabled = false
//       }
//       if(el.files&&el.files.length){
//         bianli(el.files)
//       }
//     })
//   }
// }

export default {
	name: "addJQDialog",
	components: {
		appdialog,
	},
	data() {
    return {
      loading:false,
      isshow:false,
      treedata:[],
      nowChoose:'',
      nowObj:{},
      defaultProps: {
        children: 'files',
        label: 'name',
      }
    }
  },
  mounted() {
  	
  },
	methods:{
    //选择文件
    handleNodeClick(data) {
      if(data.fileType == 2){
        this.isshow = true,
        this.nowChoose = data.name
      }
      this.nowObj = data
    },
   	open(){
       this.$refs.dialog.open()
       this.isshow = false
       this.nowChoose = ''
       this.loading = true
       //获取服务端文件树
       getDirFile({}).then(ret=>{
       this.loading = false
         console.log(ret.data)
         if(ret&&ret.code == 0){
           this.treedata = ret.data.files
         }
       })
    },
		close(){
			this.$refs.dialog.close();
		},
   	confirmAdd(){
       //选择并且选择的是文件
   		if(this.nowChoose && this.nowObj.fileType == 2){
         this.$emit('addSucess',this.nowObj)
      }else{
        setTimeout(()=>{
          this.open()
        },50)
      }
   	},
   	cancleAdd(){
      this.loading = false
   	},
	}
}
</script>

<style scoped lang="scss">
@import "../../../styles/variables.scss";


</style>